package com.nekoneko.nekonekodemo.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.nekoneko.nekonekodemo.R;
import com.nekoneko.nekonekodemo.ui.WheelView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


public class WheelFragment extends Fragment {
    ArrayList<String> dataList = new ArrayList<>();
    AlertDialog dialog;
    @BindView(R.id.infoShow)
    TextView infoShow;
    Unbinder unbinder;

    protected void initView() {
        dataList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            dataList.add(i + "个房间");
        }
        infoShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog();
            }
        });

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.wheel_activity, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    public void showDialog() {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_rsvprice, null);
        WheelView wheelView = (WheelView) view.findViewById(R.id.rsv_priceCode);
        WheelView roomView = (WheelView) view.findViewById(R.id.rsv_room);
        wheelView.setData(dataList);
        roomView.setData(dataList);
        dialog = new AlertDialog.Builder(getActivity()).create();
        dialog.show();
        Window window = dialog.getWindow();
//        window.setBackgroundDrawable(getResources().getDrawable(R.drawable.white_border));
//        window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.gravity = Gravity.BOTTOM;
        Display display = window.getWindowManager().getDefaultDisplay();
        layoutParams.height = display.getHeight() / 3;
        layoutParams.width = display.getWidth() * 9 / 10;
        window.setAttributes(layoutParams);
        window.setContentView(view);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
